package locate

import (
	"ones-objects/lib/mq"
	"ones-objects/config"
	"time"
	"strconv"
)

func Locate(name string) string {
	conf := mq.RabbitConf{
		Dsn: config.GetString(config.RABBITMQ_DSN),
		Queue: config.GetString(config.RABBITMQ_QUEUE_DATA),
		Exchange: config.GetString(config.RABBITMQ_EXCHANGE_DATA),
	}

	mq := mq.New(conf)

	mq.Publish(config.DATASERVERS, name)
	msgs := mq.Consume()

	go func() {
		time.Sleep(time.Second)
		mq.Close()
	}()

	msg := <- msgs

	content,_ := strconv.Unquote(string(msg.Body))
	return content
}
